// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init({
  env: cloud.DYNAMIC_CURRENT_ENV
})
const db = cloud.database();

// 云函数入口函数
exports.main = async (event, context) => {
  const wxContext = cloud.getWXContext();
  let identity_id = event.identity_id;
  let openid = wxContext.OPENID;
  let initial_id = event.initial_id;
  let custom_list = [{
    title: '扫码提货',
    tip: '扫描卡面二维码，即可提货',
    icon: 'qrcode',
    bindtap: 'scanCode',
    info: ''
  }, {
    title: '卡密提货',
    tip: '输入卡号和密码，完成提货',
    icon: 'vipcard',
    bindtap: 'toCardPicking',
    info: ''
  }, {
    title: '我的订单',
    tip: '查看本账户的历史订单情况',
    icon: 'form',
    bindtap: 'toOrder',
    info: ''
  }];
  let add_list = [{
    title: '切换身份',
    tip: '点击按钮可切换为商家身份',
    icon: 'order',
    bindtap: 'changeIdentity',
    info: '2'
  }];
  let business_list = [{
    title: '商品管理',
    tip: '签发卡券前需要先发布商品',
    icon: 'goods',
    bindtap: 'navigateToPage',
    info: '../business/goods/goods'
  }, {
    title: '卡券管理',
    tip: '商家在线签发卡券且可导出',
    icon: 'punch',
    bindtap: 'navigateToPage',
    info: '../business/lssueCard/lssueCard'
  }, {
    title: '商家发货',
    tip: '商家通过扫码实现快速发货',
    icon: 'deliver',
    bindtap: 'navigateToPage',
    info: '../business/deliverGoods/deliverGoods'
  }, {
    title: '切换身份',
    tip: '点击按钮可切换为顾客身份',
    icon: 'order',
    bindtap: 'changeIdentity',
    info: '1'
  }];
  let res = new Object();
  res.openid = openid;
  if (identity_id == 1) {
    // if(initial_id == 2){
    //   res.list = custom_list.concat(add_list);
    // }else{
    //   res.list = custom_list;
    // }
    res.list = custom_list.concat(add_list);
  } else if (identity_id == 2) {
    res.list = business_list;
  }
  return res;
}